package com.wmx.hb.controller;

import com.wmx.hb.enums.ResultCode;
import com.wmx.hb.pojo.ResultData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @author wangMaoXiong
 * @version 1.0
 * @date 2021/7/4 17:58
 */
@RestControllerAdvice
public class AppExceptionController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 自定义异常以外的异常，统一处理
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResultData<Object> handleException(Exception e) {
        logger.error(e.getMessage(), e);
        ResultData<Object> resultData = new ResultData<>(ResultCode.FAIL, e.getMessage());
        return resultData;
    }

    //自定义异常处理

}
